/**
 * @author baz
 */
package bot {
import bot.state.IBotState;

import flash.display.Shape;
import flash.display.Sprite;

import lib.ObjectUtils;

import mvc.AppSettings;

public class BotView extends Sprite implements IFrameObject {
    private static const ROTATE_SPEED:int = 5;

    private var state:IBotState;
    private var stateList:BotStateList;

    private var botView:BotGreen;
    private var ship:Ship;

    public function getState():IBotState {
        return state;
    }

    public function BotView() {
        ObjectUtils.showRegister(this);

        stateList = new BotStateList(this);
        setState(BotStateList.IDLE);

        ship = new Ship();
        addChild(ship);

        botView = new BotGreen();
        addChild(botView);
    }

    /**
     * @param stateId
     * @param params
     */
    public function setState(stateId:int, ...params):void {
        state = stateList.getById(stateId);
        state.init.apply(null, params);
    }

    /**
     * Check for current state
     * @param stateId
     * @return
     */
    public function inState(stateId:int):Boolean {
        return state == stateList.getById(stateId);
    }

    public function frameHandler():void {
        state.frameHandler();
    }

    public function rotateClockWise():void {
        ship.rotation += ROTATE_SPEED;
    }

    public function rotateAntiClockWise():void {
        ship.rotation -= ROTATE_SPEED;
    }

    public function moveLeft():void {
        botView.moveLeft();
    }

    public function moveRight():void {
        botView.moveRight();
    }
}
}
